import { applyMiddleware, compose, createStore } from 'redux';
import thunk from 'redux-thunk';
import { createLogger } from 'redux-logger';
import rootReducer from '../reducers';

const logger = createLogger({ collapsed: true });
const isDev = process.env.NODE_ENV;

const middlewareArr = [thunk];
if (isDev) middlewareArr.push(logger);

function configureStore(preloadedState) {
  return createStore(
    rootReducer,
    preloadedState,
    compose(
      applyMiddleware(...middlewareArr),
    ),
  );
}

export default configureStore()